#include <bits/stdc++.h>
using namespace std;
struct Pipe {
    int len;//length
    int dia;//diameter
    int num;//number

} p[100000];
int n;
bool myCmp(Pipe a, Pipe b) {
    if(a.len!=b.len)return b.len<a.len;//dec //a.len<b.len inc
    if(a.dia!=b.dia)return a.dia<b.dia;
    return b.num<a.num;

}
int main() {
//	freopen("A.in","r",stdin);
    int T;
    cin>>T;
    while(T--){

        cin >> n;
        for(int i = 0; i < n; i++)cin >> p[i].len >> p[i].dia >> p[i].num;
        sort(p, p + n, myCmp);
        cout<<p[0].num<<endl;
    }
    return 0;
}

/**
4
3000 50 872198442
3000 45 752498124
2000 60 765128742
3000 45 652278122
*/
